package codeTop;

import java.util.ArrayList;
import java.util.List;

public class q78 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        dfs(res,list,nums,0);
        return res;
    }

    private void dfs(List<List<Integer>> res, List<Integer> list, int[] nums, int idx) {
        if (idx == nums.length) {
            res.add(List.copyOf(list));
            return;
        }
        //不加入当前元素
        dfs(res,list,nums,idx+1);
        //加入当前元素
        list.add(nums[idx]);
        dfs(res,list,nums,idx+1);
        list.remove(list.size()-1);
    }
}
